//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Eas.WebCrawler.Test.Model {
    /// <summary>
    /// Summary description for TestBaseWebCrawlerContext
    /// </summary>
    [TestClass]
    public class BaseWebCrawlerContextTest {
        public BaseWebCrawlerContextTest() {
            //
            // TODO: Add constructor logic here
            //
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup() {
            GC.Collect();
        }
        //
        #endregion

        [TestMethod]
        public void TestMethod1() {
            TestSettings settings = new TestSettings();
            string[] startingUris = new string[] { "http://www.google.com", "http://www.msn.com" };
            settings.StartingUris = startingUris;
            Eas.WebCrawler.Model.Events.BaseWebCrawlerEvents events = new Eas.WebCrawler.Model.Events.BaseWebCrawlerEvents();
            Eas.WebCrawler.Model.Core.BaseRequestStore store = new Eas.WebCrawler.Model.Core.BaseRequestStore();

            using (Eas.WebCrawler.Model.Core.BaseWebCrawlerContext context = new Eas.WebCrawler.Model.Core.BaseWebCrawlerContext(settings, store, events)) {
                Assert.AreSame(settings.CompletedRequestHistory, context.CompletedRequestHistory);
                Assert.AreSame(settings.LinkExtractor, context.LinkExtractor);
                Assert.AreSame(settings.RequestPriorityComparer, context.RequestPriorityComparer);
                Assert.AreSame(settings.Selector, context.Selector);
                Assert.AreEqual<int>(settings.SleepTimeInMilliseconds, context.SleepTimeInMilliseconds);
                Assert.AreSame(startingUris, context.StartingUris);
                Assert.AreSame(settings.StorageFactory, context.StorageFactory);
                Assert.AreEqual<int>(settings.TimeoutInMilliseconds, context.TimeoutInMilliseconds);
                Assert.AreEqual<int>(settings.WorkerCount, context.WorkerCount);
                Assert.AreSame(store, context.Store);
                Assert.AreSame(events, context.Events);
                events.Fire_Starting();
                Assert.AreEqual<int>(2, store.Count);
            }
        }
    }
}
